// createRouter: 创建router实例对象
// createWebHistory: 创建history模式的路由
import {createRouter, createWebHistory} from 'vue-router'
import Layout from '@/views/layout/index.vue'
import Login from '@/views/login/index.vue'
import Home from '@/views/home/index.vue'
import Category from '@/views/category/index.vue'
import SubCategory from '@/views/subCategory/index.vue'
import Detail from '@/views/Detail/index.vue'
import CartList from '@/views/CartList/index.vue'
import CheckOut from '@/views/CheckOut/index.vue'
import Pay from '@/views/Pay/index.vue'
import PayBack from "@/views/Pay/PayBack.vue";
import Member from '@/views/Member/index.vue'
import MemberUserInfo from '@/views/Member/UserInfo/index.vue'
import MemberUserOrder from '@/views/Member/UserOrder/index.vue'


const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    // path 和 components 对应关系的位置
    routes: [
        {
            path: '/',
            component: Layout,
            children: [
                {
                    path: '',
                    component: Home,
                },
                {
                    path: 'category/:id',
                    name: 'category',
                    component: Category,
                },
                {
                    path: 'category/sub/:id',
                    name: 'subCategory',
                    component: SubCategory,
                },
                {
                    path: 'detail/:id',
                    name: 'detail',
                    component: Detail,
                },
                {
                    path: 'cartlist',
                    name: '购物车',
                    component: CartList,
                },
                {
                    path: 'checkout',
                    name: '结算页面',
                    component: CheckOut,
                },
                {
                    path: 'pay',
                    name: '支付',
                    component: Pay,
                },
                {
                    path: 'paycallback',
                    name: '支付结果',
                    component: PayBack,
                },
                {
                    path: 'member',
                    name: '会员中心',
                    component: Member,
                    children: [
                        {
                            path: '',
                            name: '会员中心-用户信息',
                            component: MemberUserInfo
                        },
                        {
                            path: 'order',
                            name: '会员中心-用户订单',
                            component: MemberUserOrder
                        }
                    ]
                },

            ]
        },
        {
            path: '/login',
            component: Login
        }

    ],
    // 路由跳转时，滚动条回到顶部
    scrollBehavior() {
        return {
            left: 0,
            top: 0
        }
    }
})

export default router
